﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SpiceNet.Circuits;
using SpiceNet.Diagnostics;

namespace SpiceNet.Simulations
{
    public class TranJob : Job
    {
        /// <summary>
        /// The final time of the transient simulation
        /// </summary>
        public double TRANfinalTime;

        /// <summary>
        /// The step parameter for the transient simulation
        /// </summary>
        public double TRANstep;

        /// <summary>
        /// The time when data should be stored
        /// </summary>
        public double TRANinitTime;

        /// <summary>
        /// The maximum step
        /// </summary>
        public double TRANmaxStep;

        /// <summary>
        /// The transient mode
        /// </summary>
        public Circuit.Modes TRANmode;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name"></param>
        public TranJob(string name)
            : base(name)
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name"></param>
        /// <param name="maxStep"></param>
        /// <param name="finalTime"></param>
        public TranJob(string name, double step, double finalTime)
            : base(name)
        {
            TRANstep = step;
            TRANfinalTime = finalTime;
        }

        /// <summary>
        /// Gets or sets parameters
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public override object this[string key]
        {
            get
            {
                switch (key)
                {
                    case "tstart": return TRANinitTime;
                    case "tstop": return TRANfinalTime;
                    case "tstep": return TRANstep;
                    case "tmax": return TRANmaxStep;
                    case "uic": return TRANmode.HasFlag(Circuit.Modes.Uic);
                    default:
                        CircuitWarning.Warning(this, string.Format("Unrecognized parameter {0} for job {1}", key ?? "NULL", Name));
                        return null;
                }
            }
            set
            {
                switch (key)
                {
                    case "tstart": TRANinitTime = Convert.ToDouble(value); break;
                    case "tstop": TRANfinalTime = Convert.ToDouble(value); break;
                    case "tstep": TRANstep = Convert.ToDouble(value); break;
                    case "tmax": TRANmaxStep = Convert.ToDouble(value); break;
                    case "uic":
                        bool flag = Convert.ToBoolean(value);
                        if (flag)
                            TRANmode = Circuit.Modes.Uic;
                        else
                            TRANmode = 0;
                        break;
                }
            }
        }
    }
}
